import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import './assets/font-awesome-4.7.0/css/font-awesome.min.css'
Vue.config.productionTip = false;

Vue.use(ElementUI);


import VueDND from 'awe-dnd'
Vue.use(VueDND)
/* base style */
import './../static/lib/css/base.less'
// Axios
import axios from 'axios'
import * as api from './api/api'
import { loginPath } from './config/env'
/* @desc:httpInterceptor */
import {request,response} from './config/httpInterceptor'
axios.interceptors.request.use(request)
axios.interceptors.response.use(response);

/*filter*/
import filter from './config/filter.js'
Vue.use(filter)

/*method*/
import pluginMethod from './config/method.js'
Vue.use(pluginMethod)

/*VueLazyLoad*/
import VueLazyLoad from 'vue-lazyload'
Vue.use(VueLazyLoad,{
    error:require('./assets/img/image.png'),
    loading:require('./assets/img/image.png')
})


router.beforeEach((to, from, next) => {  
	if (to.meta){
		document.title = to.meta;
	  }
	api.loginStatus().then(res=>{
		if(res.data.code==401){
			next(window.location.href=loginPath)
		}else{
			next(); 
		}
	}).catch(err=>{
		if(err.response.status==401){
			window.location.href=loginPath
		}
	});
  }); 

new Vue({
	el: '#app',
	router,
	store,
	template: '<App/>',
	components: { App }
})
